package cn.kgc.springboot.vue.controller;

import cn.kgc.springboot.vue.commons.QueryCondition;
import cn.kgc.springboot.vue.entity.Score;
import cn.kgc.springboot.vue.response.ResponseResult;
import cn.kgc.springboot.vue.service.ScoreService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

/**
 * @author 课工场
 * @date 2024/12/30
 * @description
 */
@RestController
@RequestMapping("score")
public class ScoreController {

    @Resource
    private ScoreService scoreService;

    @PostMapping("page")
    public ResponseResult scorePage(@RequestBody QueryCondition<Score> queryCondition) {
       return   scoreService.scorePage(queryCondition);
    }


    @PostMapping("addOrUpdate")
    public ResponseResult addOrUpdateScore(@RequestBody Score score) {
        scoreService.saveOrUpdate(score);
        return ResponseResult.success();
    }


    @PostMapping("batchAdd")
    public ResponseResult  batchAdd(MultipartFile file){
       return  scoreService.batchAdd(file);
    }


    @DeleteMapping("delete/{id}")
    public ResponseResult  deleteScore(@PathVariable("id") Integer id){
        scoreService.removeById(id);
        return ResponseResult.success();
    }

    @PostMapping("export")
    public void   exportScore(@RequestBody HashMap<String,String> params, HttpServletResponse response) {
        scoreService.exportScore(params,response);
    }


}
